<template>
    <view class="outwrep">
        <view class="tabtwo">
            <view class="tabas tabpublic" @click="pushaFn">
                <view class="leftl">今日总盈利(USDT)</view>
				<view style="font-family: Aileron;color: #FFF12A;font-size: 22px;">{{todayProfit}}</view>
            </view>
            <view class="tabbs tabpublic" @click="pushbFn">
                <view class="leftl">累计总盈利(USDT)</view>
				<view style="font-family: Aileron;color: #FFF12A;font-size: 22px;">{{totalProfit}}</view>
            </view>
        </view>
		<view class="leftcont" v-if="isShowhide=='1'">
		    <view class="vofrs" v-for="(item,index) in todayList" :key="index">
				<view>
					<view class="lines">
					    <text class="txta">订单编码：</text>
					    <text class="txtb">{{item.flowOrderId}}</text>
					</view>
					<view class="lines">
					    <text class="txta">平仓币种：</text>
					    <text class="txtb">{{item.coin}}·{{item.note}}X</text>
					</view>
					<view class="lines">
					    <text class="txta">平仓时间：</text>
					    <text class="txtb">{{item.createTime}}</text>
					</view>
					<view class="lines">
					    <text class="txta">盈利额度：</text>
					    <text class="txtb">{{item.amount}}</text>
					</view>
				</view>
				<view>
					<image class="exchangeImg" v-if="item.exchangeType==0" src="../../static/img/ind0.png"></image>
					<image class="exchangeImg" v-if="item.exchangeType==1" src="../../static/img/ind2.png"></image>
					<image class="exchangeImg" v-if="item.exchangeType==2" src="../../static/img/ind1.png"></image>
				</view>
		    </view>
			<view v-show="isLoadMore1">
			    <uni-load-more :status="loadStatus1"></uni-load-more>
			</view>
		</view>
		<view class="rightcont" v-if="isShowhide=='2'">
		    <view class="vogrs" v-for="(item,index) in totalList" :key="index">
				<view class="threx">
				    <view>
						<image class="exchangeImgSmall" v-if="item.exchangeType==0" src="../../static/img/ind0.png"></image>
				    	<image class="exchangeImgSmall" v-if="item.exchangeType==1" src="../../static/img/ind2.png"></image>
				    	<image class="exchangeImgSmall" v-if="item.exchangeType==2" src="../../static/img/ind1.png"></image>
				    </view>
				    <text class="txtrighb">{{item.coin}}·{{item.note}}X</text>
				    <text class="txtrighc">{{item.flowOrderId}}</text>
				</view>
				<view class="threx">
				    <text class="txtrigha">盈利</text>
				    <text class="txtrighb">{{item.amount}} USDT</text>
				    <text class="txtrighc">{{item.createTime}}</text>
				</view>
		    </view>
			<view v-show="isLoadMore2">
			    <uni-load-more :status="loadStatus2"></uni-load-more>
			</view>
		</view>
        <backTop :src="backTop.src"  :scrollTop="backTop.scrollTop"></backTop>
    </view>
</template>

<script>
    let uinfo;
    import request from "../../untils/request.js";
	import backTop from '../../components/back-top/back-top.vue';
    export default {
		components: {
		    backTop
		},
		onPageScroll(e) {
			this.backTop.scrollTop = e.scrollTop;
		},
        data() {
            return {
				scrollTop: 0,
				backTop: {
					src: '../../static/top.png',
					scrollTop: 0
				},
                isShowhide: '1',
                todayProfit: '',
                totalProfit: '',
                todayList: [],
                totalList: [],
				loadStatus1: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore1: false, //是否加载中
				loadStatus2: 'loading', //加载样式：more-加载前样式，loading-加载中样式，nomore-没有数据样式
				isLoadMore2: false, //是否加载中
				page1: 1,
				page2: 1,
				limit1: 10,
				limit2: 10
            }
        },
        onLoad() {
            uinfo = uni.getStorageSync('userInfo');
            //console.log(uinfo)
            this.profitFn();

            this.listaFn();
        },
        onShow() {
            console.log(this.getCurrentDateTime())
        },
		onReachBottom() { //上拉触底函数
		    if(this.isShowhide == '1'){
		        if (!this.isLoadMore1) { //此处判断，上锁，防止重复请求
		            this.isLoadMore1 = true;
		            this.page1++;
		   	        this.listaFn();
		        }	
		    }else if(this.isShowhide == '2'){
			    if (!this.isLoadMore2) { //此处判断，上锁，防止重复请求
			        this.isLoadMore2 = true;
			        this.page2++;
			        this.listbFn();
			    }	
		   }
		},
        onPullDownRefresh() {
            console.log('refresh');
            if(this.isShowhide == '1'){
				this.page1 = 1;
            	this.listaFn();
            }else if(this.isShowhide == '2'){
				this.page2 = 1;
            	this.listbFn();
            }
        },
        methods: {
            //今日盈利---累计盈利
            profitFn() {
                request.postAssets('/assets/userWalletInfo/queryUserWalletInfo', {
                    userId: uinfo.userId,
                    pageNumber: 1,
                    pageSize: 10
                }).then(res => {
                    if (res.code == '200') {
                        this.todayProfit = res.data.items[0].todayProfit;
                        this.totalProfit = res.data.items[0].totalProfit;
                    } else {
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
			pushaFn(){
				this.page1 = 1;
				this.isShowhide = '1';
				this.listaFn();
			},
            listaFn() {
                request.postAssets('/assets/walletAssetsFlow/queryWalletAssetsFlow', {
                    userId: uinfo.userId,
                    pageNumber: this.page1,
                    pageSize: this.limit1,
                    type: 7,
                    createTimeStart: this.getCurrentDateTime() + ' 00:00:00',
                    createTimeEnd: new Date().getTime(),
					sortType: 'descend',
					sortAttribute: '2'
                }).then(res => {
                    //console.log(res)
                    if (res.code == '200') {
						uni.stopPullDownRefresh();
						if (res.data.items.length > 0){
							if(this.page1 == 1){
								this.todayList = res.data.items;
							}else{
								this.todayList = this.todayList.concat(res.data.items);
							}
							//如果最后一页小于每页限制数
							if (res.data.items.length < this.limit1) {
							    this.isLoadMore1 = true;
							    this.loadStatus1 = 'nomore';
							} else {
							    this.isLoadMore1 = false;
								this.loadStatus1 = 'more';
							}
						}else{
							this.isLoadMore1 = true;
							this.loadStatus1 = 'nomore';
						}
                    } else {
                        uni.stopPullDownRefresh();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
			pushbFn(){
				this.page2 = 1;
				this.isShowhide = '2';
				this.listbFn();
			},
            listbFn() {
                request.postAssets('/assets/walletAssetsFlow/queryWalletAssetsFlow', {
                    userId: uinfo.userId,
                    pageNumber: this.page2,
                    pageSize: this.limit2,
                    type: 7,
					sortType: 'descend',
					sortAttribute: '2'
                }).then(res => {
                    if (res.code == '200') {
						uni.stopPullDownRefresh();
						if (res.data.items.length > 0){
							if(this.page2 == 1){
								this.totalList = res.data.items;
							}else{
								this.totalList = this.totalList.concat(res.data.items);
							}
							//如果最后一页小于每页限制数
							if (res.data.items.length < this.limit2) {
							    this.isLoadMore2 = true;
							    this.loadStatus2 = 'nomore';
							} else {
							    this.isLoadMore2 = false;
								this.loadStatus2 = 'more';
							}
						}else{
							this.isLoadMore2 = true;
							this.loadStatus2 = 'nomore';
						}
                    } else {
                        uni.stopPullDownRefresh();
                        uni.showToast({
                            icon: "none",
                            title: res.message,
                        });
                    }
                })
            },
            getCurrentDateTime() {
                function formatZero(n) {
                    if (n >= 0 && n <= 9) {
                        return "0" + n;
                    } else {
                        return n;
                    }
                }
                var date = new Date();
                var year = date.getFullYear();
                var month = date.getMonth() + 1;
                var day = date.getDate();
                var hours = date.getHours();
                var minutes = date.getMinutes();
                var seconds = date.getSeconds();
                return year + "-" + formatZero(month) + "-" + formatZero(day);
                //+" "+formatZero(hours)+":"+formatZero(minutes)+":"+formatZero(seconds)
            }
        }
    }
</script>

<style>
    .outwrep {
        background: #f5f5f5;
    }

    .tabtwo {
        display: flex;
        justify-content: space-between;
        padding: 0 10px 15px;
        background: #FFFFFF;
    }

    .tabtwo .tabpublic {
		display: flex;
		flex-direction: column;
        width: 334rpx;
        height: 200rpx;
		align-items: center;
		justify-content: center;
    }

    .tabtwo .tabas {
        background: url('../../static/img/jryl.png') no-repeat;
        background-size: contain;
    }

    .tabtwo .tabbs {
        background: url('../../static/img/ljjr.png') no-repeat;
        background-size: contain;
    }

    .tabtwo .tabas image {
        width: 167px;
        height: 100px;
    }

    .tabpublic .leftl {
        font-size: 15px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 25px;
        color: #FFFFFF;
    }

    .leftcont {
        margin: 10px 0 0 0;
        background: #FFFFFF;
    }

    .leftcont .vofrs {
		display: flex;
		justify-content: space-between;
        border-bottom: 1px solid #EBEBEB;
        margin: 0 10px;
        padding: 15px 0 15px 0;
    }

    .leftcont .txta {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 25px;
        color: #ADB0BB;
    }

    .leftcont .txtb {
        font-size: 16px;
        font-family: Aileron;
        font-weight: 400;
        line-height: 25px;
        color: #333333;
    }

    .rightcont {
        margin: 10px 0 0 0;
        background: #FFFFFF;
    }

    .rightcont .vogrs {
        border-bottom: 1px solid #EBEBEB;
        margin: 0 10px;
        padding: 15px 0 15px 0;
    }

    .rightcont .threx {
        display: flex;
        justify-content: space-between;
    }

    .rightcont .txtrigha {
        font-size: 16px;
        font-family: Source Han Sans CN;
        font-weight: 400;
        line-height: 25px;
        color: #6E6E6E;
    }

    .rightcont .txtrighb {
        font-size: 16px;
        font-family: Aileron;
        font-weight: 400;
        line-height: 25px;
        color: #333333;
    }

    .rightcont .txtrighc {
        font-size: 14px;
        font-family: Aileron;
        font-weight: 400;
        line-height: 25px;
        color: #ADB0BB;
    }
	
	.exchangeImg {
		width: 60px;
		height: 60px;
	}
	
	.exchangeImgSmall {
		width: 20px;
		height: 20px;
	}
</style>
